const http = require("http");
const fs = require("fs");
const path = require("path");

const filePath = path.join(__dirname, "/get.html");
http.createServer((req, res) => {
    if (req.url == "/") {
        var fileContent = fs.readFileSync(filePath);
        res.writeHead(200, { "Content-Type": "text/html;charset=utf-8" });
        res.write(fileContent);
        res.end();
    } else {
        var urlObj = new URL(req.url, "http://localhost:8081/");
        // 提取请求的参数
        var newsId = urlObj.searchParams.get("newsId");
        console.log(urlObj);
        // console.log(req.url);
    }
}).listen(8081);
console.log("listening on port 8081");
